<template>
  <view class="goodsitem">
    <view class="img">
      <!-- 单选选中的状态 -->
      <radio @click="changeStatus" v-if="showRadio" color="#c00000" :checked="item.goods_status" />
      <image :src="item.goods_small_logo ? item.goods_small_logo : defaultPic" mode="aspectFill"></image>
    </view>
    <view class="info">
      <view class="title">
        {{ item.goods_name }}
      </view>
      <view class="price">
        ￥{{ item.goods_price | tofixed }}
        <uni-number-box @change="numChange" v-if="showNum" v-model="item.goods_count"></uni-number-box>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "my-goods",
    props: {
      item: {
        type: Object,
        default: {}
      },
      showRadio:{
        type:Boolean,
        default:false
      },
      showNum:{
        type:Boolean,
        default:false
      }
    },
    data() {
      return {

      };
    },
    filters: {
      // 把数字处理为带两位小数点的数字
      tofixed(num) {
        return Number(num).toFixed(2)
      }
    },
    methods:{
      numChange(value){
        this.$emit('num-change',{
          goods_id:this.item.goods_id,
          goods_count:value
        })
      },
      changeStatus(){
        // 点击radio的时候会触发
        this.$emit('radioChange',{
          goods_id:this.item.goods_id,
          goods_status:!this.item.goods_status
        })
      }
    }
  }
</script>

<style lang="scss">
  .goodsitem {
    display: flex;
    padding: 10px 10px;
    border-bottom: 1px solid #ccc;

    .img {
      display: flex;
      align-items: center;
      image {
        width: 130px;
        height: 90px;
      }
    }

    .info {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 6px 0px;
      margin-left: 10px;

      .title {
        font-size: 14px;
        word-break: break-all;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        /* 这里是超出几行省略 */
        overflow: hidden;
      }

      .price {
        color: #c00000;
        display: flex;
        justify-content: space-between;
      }
    }
  }
</style>
